package net.cyan.commons.util;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2006</p>
 * <p>Company: </p>
 *
 * @author ccs
 * @version 1.0
 */

public class KeyValue<V> implements Value<String>
{
    private static final long serialVersionUID = 6L;

    private String key;

    private V value;

    public KeyValue()
    {
    }

    public KeyValue(String key, V value)
    {
        this.key = key;
        this.value = value;
    }

    public String getKey()
    {
        return key;
    }

    public void setKey(String key)
    {
        this.key = key;
    }

    public V getValue()
    {
        return value;
    }

    public void setValue(V value)
    {
        this.value = value;
    }

    public String toString()
    {
        return value == null ? "" : value.toString();
    }

    public String valueOf()
    {
        return key;
    }

    public boolean equals(Object obj)
    {
        if (obj instanceof Value)
            obj = ((Value) obj).valueOf();

        if (key == null)
            return obj == null;

        return key.equals(obj);
    }

    public int hashCode()
    {
        return key == null ? 0 : key.hashCode();
    }
}